package utils

import (
	"github.com/spf13/cast"
	"strconv"
	"time"
)

// 按天生成日期数据
func GenerateDayList(startDate, endDate time.Time) []string {
	dateList := []string{}
	currentDate := startDate

	for !currentDate.After(endDate) {
		dateList = append(dateList, currentDate.Format("2006-01-02"))

		// 增加一天
		currentDate = currentDate.AddDate(0, 0, 1)
	}

	return dateList
}

// 按月生成日期数据
func GenerateMonthList(startDate, endDate time.Time) []string {
	dateList := []string{}
	currentDate := startDate

	for !currentDate.After(endDate) {
		dateList = append(dateList, currentDate.Format("2006-01"))

		// 增加一个月
		currentDate = currentDate.AddDate(0, 1, 0)
	}

	return dateList
}

// 按年生成一年的数据
func GenerateYearList(year string) []string {
	dateList := make([]string, 0)
	// 获取当前年份
	for i := 1; i < 13; i++ {
		if i < 10 {
			date := cast.ToString(year) + "-0" + cast.ToString(i)
			dateList = append(dateList, date)
		} else {

			dateList = append(dateList, cast.ToString(year)+"-"+cast.ToString(i))
		}
	}
	return dateList
}

// 在月份或日期小于10时，在前面补零
func PadZero(num int) string {
	str := strconv.Itoa(num)
	if num < 10 {
		str = "0" + str
	}
	return str
}
